from Products.Archetypes.public import *
from Products.CMFCore import permissions
from Products.sdotNews.config import *

""" 
   a slashdot / squishdot like folderish type
"""

schema = BaseSchema +  Schema((
        StringField('id',
                 required=1, 
                 mode="rw",
                 accessor="getId",
                 mutator="setId",
                 default=None,
                 widget=IdWidget(
                 label="Short Name",
                 label_msgid="label_short_name",
                 description="Should not contain spaces, underscores or mixed case. "\
                 "Short Name is part of the item's web address.",
                 description_msgid="help_shortname",
                 visible={'view' : 'visible'},
                 i18n_domain="plone"),
                 ),
    StringField('title',
                required=1,
                searchable=1,
                default='',
                accessor='Title',
                widget=StringWidget(label="Title",
                                    label_msgid="label_title",
                                    description="The title of your folder. This will show up in the navigation.",
                                    description_msgid="help_title",
                                    i18n_domain="sdotNews"),
                ),    
    StringField('description',
                isMetadata=1,
                accessor='Description',
                widget=TextAreaWidget(label='Description', 
                                label_msgid='label_sdotnews_desc',
                                description='A brief description of the news category.',
                                description_msgid="help_description",
                                i18n_domain="sdotNews"), 
               ),
    ImageField('sdot_folder_icon',
                   widget=ImageWidget(label='News folder icon',
                                      label_msgid='label_sdotnews_icon',
                                      description='The icon is used to display news categories.',
                                      description_msgid='help_sdotnews_icon',
                                      i18n_domain='sdotNews')),
    ))


    
new_actions = (
    {'id': 'sdotrssfeed',
     'name': 'RSS Feed',
     'action': "string:${object_url}/sdotnews-rss.xml",
     'permissions': (permissions.View,),
     'category': 'document_actions',
     },)
     
    
def modify_fti(fti):
    fti['actions'] = fti['actions'] + new_actions

    
class sdotNewsFolder(OrderedBaseFolder):
    """
        A sdotNewsFolder stores News in a slashdot / squishdot like style
    """
    schema = schema
    filter_content_types = 1
    allowed_content_types = ('News Item', 'sdotNewsFolder','PloneArticle') 
    meta_type = 'sdotNewsFolder'
    archetype_name = 'sdot News Folder'
    
    content_icon = 'sdotFolder_icon.png'
    actions = ({
       'id': 'view',
        'name': 'View',
        'action': 'string:${object_url}/sdotnews_view',
        'permissions': (permissions.View,)
        },
        {'id': 'references',
          'name': 'References',
          'action': 'string:${object_url}/reference_edit',
          'permissions': (permissions.ModifyPortalContent,),
          'visible':0},
        {'id': 'metadata',
          'name': 'Properties',
          'action': 'string:${object_url}/base_metadata',
          'permissions': (permissions.ModifyPortalContent,),
          'visible':0},
        {'id': 'local_roles',
            'name': 'Sharing',
            'action': 'string:${object_url}/folder_localrole_form',
            'permissions': (permissions.ManageProperties)
          },)    
#        { 'id': 'edit',
#                  'name': 'Edit',
#                  'action': 'portal_form/base_edit',
#                  'permissions': (permissions.ModifyPortalContent,),
#                  'category':'folder',
#                  })
                  
                  
registerType(sdotNewsFolder)
